% by clq sby
function [i_R, profits_R, EYI, EYin, ProfitPart] = round_robin(j_all, N)
    addpath functions;
    global I J P CURRENT
    profits_R = zeros(1, N);
    ProfitPart = zeros(J, N);
    EYI = zeros(1, N);
    EYin = zeros(1, N);
    %j_all is the given order of patient types
    S = zeros(I, J);
    i_R = zeros(1, N);
    Q = ones(I, 1);
    %Step1:find the optimal slot for each patient
    for n = 1:N
        CURRENT = n;
        Q = [Q, zeros(I,1)];
        i_R(1, n) = mod(n-1, I) + 1; 
        %Step2:find the profit after each patient is assigned
        j = j_all(n);
        S(i_R(1,n), j) = S(i_R(1,n), j) + 1;
        Q = findQ2(Q, i_R(1,n), j, P, n); 
        R = findR(Q);
        [profits_R(n), EYI, EYin, ProfitPart] = function_fQR(Q, R, EYI, EYin, ProfitPart);
    end
return




